From d5ab9f9089dcf8a8a336e6dff26fae6b6d4b91fd Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Thu, 24 May 2007 10:39:28 +0100 Subject: [PATCH] x86: Prevent an infinite series of traps In some cases, we can end up in a vicious cycle of fatal_trap()s within fatal_trap()s. Panic after a certain number of attempts. Signed-off-by: Nils Nieuwejaar Use a per-cpu depth variable. Signed-off-by: Keir Fraser --- xen/arch/x86/traps.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 61160cb504..fb454043eb 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -345,16 +345,26 @@ char *trapstr(int trapnr) */ asmlinkage void fatal_trap(int trapnr, struct cpu_user_regs *regs) { - watchdog_disable(); - console_start_sync(); + static DEFINE_PER_CPU(char, depth); - show_execution_state(regs); - - if ( trapnr == TRAP_page_fault ) + /* + * In some cases, we can end up in a vicious cycle of fatal_trap()s + * within fatal_trap()s. We give the problem a couple of iterations to + * bottom out, and then we just panic. + */ + if ( ++this_cpu(depth) < 3 ) { - unsigned long cr2 = read_cr2(); - printk("Faulting linear address: %p\n", _p(cr2)); - show_page_walk(cr2); + watchdog_disable(); + console_start_sync(); + + show_execution_state(regs); + + if ( trapnr == TRAP_page_fault ) + { + unsigned long cr2 = read_cr2(); + printk("Faulting linear address: %p\n", _p(cr2)); + show_page_walk(cr2); + } } panic("FATAL TRAP: vector = %d (%s)\n" -- 2.30.2